ASM=nasm

CC=gcc
CC_FLAGS=-m32 -Wall -Wextra -Werror -nostdlib -nostartfiles -nodefaultlibs

LD=ld

DD=dd

all: clean image

clean:
	rm -f *.o
	rm -f kernel.bin pad floppy.img

# C Kernel
kernel.o: kernel.c mmu.o
	$(CC) -o $@ $< $(CC_FLAGS)
mmu.o: mmu.c
	$(CC) -o $@ $< $(CC_FLAGS)

# Assembler GRUB Header 
loader.o: loader.asm
	$(ASM) -f elf32 -o $@ $<

# Kernel Binary
kernel.bin: linker.ld loader.o kernel.o
	$(LD) -m elf_i386 --format elf32-i386 -T linker.ld -o kernel.bin loader.o kernel.o

# Para crear la imagen con GRUB
pad:
	dd if=/dev/zero of=pad bs=1 count=750

image: stage1 stage2 pad kernel.bin
	cat  stage1 stage2 pad kernel.bin /dev/zero | $(DD) of=floppy.img count=1440 bs=1024